<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#Include Virtual="/expedientes/includes_comun/asp/comun.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sistemas OnLine</title>
<link href="/expedientes/includes_comun/css/general.css" rel="stylesheet" type="text/css" />
<link href="/expedientes/includes_comun/css/usuarios.css" rel="stylesheet" type="text/css" />
<link href="includes/css/sistema.css" rel="stylesheet" type="text/css" />
<script src="includes/js/botones.js" language="javascript" type="text/javascript"></script>
</head>

<body>
<div align="center" class="general-central">

	<!--#Include Virtual="/expedientes/includes_comun/areas/usuarios.asp"-->
	
	<!--#Include File="includes/areas/cabecera.asp"-->
<%
Dim gSec, Id_Secretaria
Id_Secretaria = Request.Form("secretaria")
If Len(Id_Secretaria) = 0 Then Id_Secretaria = -1 Else Id_Secretaria = CInt(Id_Secretaria)


Conectar_sol
SQL = "SELECT * FROM Secretarias where Tipo='N' ORDER BY Nombre"
Set Tabla = Conexion.Execute(SQL)
gSec = Tabla.GetRows
Tabla.Close


Conectar_gae

Select Case Request.QueryString("acc")
	Case "agregar"
		Agregar
	Case "guardar"
		Guardar
	Case "eliminar"
		Eliminar
End Select

Dim gTram
SQL = "SELECT * FROM Tramites WHERE Tipo = 'N' ORDER BY Id_Secretaria"
Set Tabla = Conexion.Execute(SQL)
gTram = Tabla.GetRows
Tabla.Close


%>	
	<div class="general-contenido">
		<span class="titulo">Tramites</span><br />
		
		<fieldset style="width: 300px; float:left;"><legend>Agregar</legend>
			<form name="agregar" method="post" action="tramites.asp?acc=agregar">
			<div>
			Nombre <input type="text" name="nombre" />
			Requisitos <textarea cols="10" rows="5" name="req"></textarea>
			Secretaria 
			<select name="id_secretaria" style="font-size:8pt;">
				<option value="0">Todas las secretarias</option>
			<% For I = LBound(gSec, 2) To UBound(gSec, 2) %>
				<option value="<%= gSec(0,I) %>"><%= gSec(1,I) %></option>
			<% Next %>
			</select>
			</div>
			<div align="center">
			<input type="submit" id="botonenviar" value="Agregar" />
			</div>
			</form>
		</fieldset>
        
      	<fieldset style="width: 421px; "><legend>Modificar / Eliminar</legend>
            <form name="tramites" method="post" action="tramites.asp">
            <select name="secretaria" onChange="document.tramites.submit();" style="font-size:8pt;">
            
                <option value="-1" selected>[ Seleccionar]</option><option value="0" <%IF Id_Secretaria = 0 THEN %> selected <%END IF%>>Todas las secretarias</option>
                <% For I = LBound(gSec, 2) To UBound(gSec, 2) %>
                    <option value="<%= gSec(0,I) %>"<%IF Id_Secretaria = gSec(0,I) THEN Response.Write("selected") END IF%>><%= gSec(1,I)&gSec(0,I) %></option>
                <% Next %>
           	</select>
		</fieldset>
           
          
            <% If Id_Secretaria <> 1 Then %>
           
            <fieldset style="width: 421px; " id="contenedormodificar" >
            <% 
				SQL = "SELECT * FROM Tramites where Tipo = 'N' AND Id_Secretaria = " & Id_Secretaria & " ORDER BY Id_Secretaria"
				Set Tabla = Conexion.Execute(SQL)
				gTram = Tabla.GetRows 
			%>
			<% For I = LBound(gTram, 2) To UBound(gTram, 2) %>
			<table style="width: 300;">
				<tr>
					<td style="width: 14px;">Sel <input type="checkbox" name="id_tramite" value="<%= gTram(0,I) %>" class="sinborde" /></td>
					<td style="width: 407px;">Nombre <input type="text" name="nombre<%= gTram(0,I) %>" value="<%= gTram(1,I) %>" style="width: 390px;" /> 
                    </td>
				</tr>
				<tr>
					<td colspan="2">
						<div>
							Secretaria
							<select name="id_secretaria<%= gTram(0,I) %>" style="width: 358px; font-size: 8pt;">
								<option value="0"<% If gTram(3,I) = 0 Then Response.Write(" selected") %>>Todas las secretarias</option>
							<% For J = LBound(gSec, 2) To UBound(gSec, 2) %>
								<option value="<%= gSec(0,J) %>"<% If gSec(0,J) = gTram(3,I) Then Response.Write(" selected") %>><%= gSec(1,J) %></option>
							<% Next %>
							</select>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2"><textarea name="req<%= gTram(0,I) %>" rows="2" style="width: 410px; "><%= gTram(2,I) %></textarea></td>
				</tr>
			</table>
			<% 
				If I < UBound(gTram, 2) Then Response.Write("<hr>")
			Next 
			%>			
			<div align="center">
				<input type="button" id="botonenviar" value="Eliminar sel" onClick="document.me.action='tramites.asp?acc=eliminar'; document.me.submit();" />
				<input type="button" id="botonenviar" value="Guardar cambios" onClick="document.me.action='tramites.asp?acc=guardar'; document.me.submit();" />
			</div>
		</fieldset>
         <% End If %>
		</form>
       
	</div>
</div>
</body>
</html>
<%
Desconectar
Sub Agregar()
	Dim Nombre, Req, Id
	Nombre = Trim(Request.Form("nombre"))
	Req = Trim(Request.Form("req"))
	Id = Request.Form("id_secretaria")
	If Len(Nombre) > 0 Then
		SQL = "INSERT INTO Tramites(Nombre, Requisitos, Id_Secretaria, Tipo) Values('" & Nombre & "','" & Req & "'," & Id & ", 'N')"
		Set Tabla = Conexion.Execute(SQL)
		MostrarMsg "El tramite se ha ingresado correctamente!", False
	Else
		MostrarMsg "Debe ingresar por lo menos un nombre de tramite!", True
	End If
End Sub

Sub Guardar()
	SQL = "SELECT * FROM Tramites WHERE Tipo = 'N'"
	Tabla.Open SQL, Conexion, 1, 2
	Do While Not Tabla.EOF
		Tabla("Nombre") = Trim(Request.Form("nombre" & Tabla("Id_Tramite")))
		Tabla("Requisitos") = Trim(Request.Form("req" & Tabla("Id_Tramite")))
		Tabla("Id_Secretaria") = Request.Form("id_secretaria" & Tabla("Id_Tramite"))
		Tabla.Update
		Tabla.MoveNext
	Loop
	Tabla.Close
	Response.Redirect("tramites.asp")
End Sub

Sub Eliminar()
	Dim Ids
	Ids = Request.Form("id_tramite")
	SQL = "SELECT * FROM Tramites WHERE Tipo = 'N' AND Id_Tramite = "&Ids&""
	Set Tabla = Conexion.Execute(SQL)
	DO WHILE NOT Tabla.EOF
		Tabla("Tipo") = "V"
		Tabla.Update
		Tabla.MoveNext
	LOOP
	Tabla.Close
	Response.Redirect("tramites.asp")
End Sub
%>